import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newFixedThreadPool(4); // 使用无界队列
        Future<?> future = executor.submit(() -> {
            try {
                Thread.sleep(1000);
                System.out.println("任务执行中...");
            } catch (InterruptedException e) {
                System.out.println("任务被中断！");
            }
        });
        boolean done = future.isDone();
        System.out.println("任务执行完了吗？ " + done);
        boolean cancelled = future.cancel(true);
        System.out.println("任务取消成功？ " + cancelled);
        executor.shutdown();
    }
}
